﻿<SearchListSpec 
    xmlns="bb_appfx_searchlist"
    xmlns:c="bb_appfx_commontypes"
    ID="81545e44-2dbc-4912-b782-b3f95c3a808c"
    Name="Organization Hierarchy Search"
    Description="Search for an Organization in the Organization Hierarchy"
    Author="Blackbaud Professional Services"
    RecordType="Organization"
    TranslationFunctionID="a317d7b1-8ea3-46ea-b04d-1f713b7efb2c"
	>
	<SPSearchList SPName="USR_USP_SEARCHLIST_TDSM_ORGANIZATION">
		<c:CreateProcedureSQL>
			<![CDATA[
create procedure dbo.USR_USP_SEARCHLIST_TDSM_ORGANIZATION
(
  @POSITION nvarchar(100) = null
 ,@MAXROWS smallint = 500
)
as
  declare @currentappuserid uniqueidentifier = null;
  exec USP_CHANGEAGENT_GETORCREATECHANGEAGENT @currentappuserid output

  declare @hierarchy table(
    isroot bit
   ,id uniqueidentifier
   ,parentid uniqueidentifier
   ,sequence int
   ,userhassiteaccess bit
   ,isvacant bit
   ,position nvarchar(max)
   ,positionholder nvarchar(max)
   ,businessunit nvarchar(max)
   );

  insert into @hierarchy
  exec USP_DATALIST_ORGANIZATIONHIERARCHY @currentappuserid

  select
    h.id
   ,POSITION
   ,POSITIONHOLDER AS FUNDRAISER
   ,BUSINESSUNIT
  from
    @hierarchy h
  where (
         (@POSITION is null)
         or
         (0 = len(@position))
         or
         (h.position like '%' + @POSITION + '%')
        );
]]>
		</c:CreateProcedureSQL>
	</SPSearchList>

    <c:FormMetaData>
		<c:FormFields>
			<c:FormField FieldID="POSITION" Caption="Position" DataType="String" MaxLength="100" />
		</c:FormFields>
	</c:FormMetaData>

    <Output TranslationField="POSITION">
		<OutputFields>
			<OutputField FieldID="ID" Caption="ID" DataType="Guid" IsHidden="true" />
			<OutputField FieldID="POSITION" Caption="Position" DataType="String" />
            <OutputField FieldID="FUNDRAISER" Caption="Fundraiser" DataType="String" />
            <OutputField FieldID="BUSINESSUNIT" Caption="Business unit" DataType="String" />
		</OutputFields>
	</Output>
</SearchListSpec>